// ==UserScript==
// @name           Vkontakte Photos Paths
// @namespace      http://polkila.googlecode.com
// @author:        Васютинский Олег
// @version:       8.04
// @include        http://vkontakte.ru/photos.php*act=album*
// @include        http://*.vkontakte.ru/photos.php*act=album*
// ==/UserScript==

(function(){
	var word = readCookie('remixlang')?'Images paths':'Ссылки на фотки';
	var summaryBar = document.evaluate('//div[@class="summary"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
	summaryBar.innerHTML+="<span class=divider>|</span><a href=# id=imglstlnk onclick='' class=notbold>"+word+" <span id=quo>»</span></a>";
	summaryBar.parentNode.innerHTML+="<div id=imagesList style='margin:10px;display:none'></div>";
	document.getElementById('imglstlnk').addEventListener('click',function(){return getImagesList();},false);
})();

var cashed = false;
function getImagesList(){	
	imagesList = document.getElementById('imagesList');
	quo = document.getElementById('quo');
	if (!cashed){
		var xpath = "//div[@id='album']//a";
		var as = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
		for (var a = null, i = 0; (a = as.snapshotItem(i)); i++) get_bigImagePath(a.href);
		cashed = true;
	}
	quo.innerHTML = quo.innerHTML=='»'?'«':'»';
	imagesList.style.display = imagesList.style.display=='none'?'block':'none';
	return false;
}

function get_bigImagePath(u){
	GM_xmlhttpRequest({method: 'GET', url: u, onload:function(result) {document.getElementById('imagesList').innerHTML+= /<img src="([^"]*)" id="myphoto"/.exec(result.responseText)[1] + "<br>";}});
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}